//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tools\fn_playerName.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_object","_result","_uid","_player_names","_default"];
DEFAULT_PARAM(_object,0,objNull);
DEFAULT_PARAM(_default,1,(str(_object)));
_result = _default;
if (!isnull _object) then {
	_uid = getPlayerUID _object;
	_player_names = OGETVAR(GVAR(mission_variables),TMF_HK_PLAYER_NAMES,(call FFUNC(hashEmpty)));
	_name = name _object;
	if (toupper(_name) == "ERROR: NO UNIT" || _name == "") then {
		_name = [_player_names,_uid,_default,THIS_FILE] call FFUNC(hashGet);
	} else {
		_player_names = [_player_names,_uid,_name] call FFUNC(hashSet);
		OSETVAR(GVAR(mission_variables),TMF_HK_PLAYER_NAMES,_player_names);
	};
	_result = _name;
};
TRACE_1("End",_result);
TMFPROFILERSTOP;
_result;